package cn.life.common.support.check;

import cn.life.common.entity.model.MyCommon;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Aspect //AOP 切面
@Component
public class MyLoginAspect {

    //切入点
    @Pointcut(value = "@annotation(cn.life.common.entity.model.MyUser)")
    private void pointcut() {

    }

    /**
     * 在方法执行前后
     *
     * @param point
     * @param myUser
     * @return
     */
    @Around(value = "pointcut() && @annotation(myUser)")
    public Object around(ProceedingJoinPoint point, MyUser myUser) {

        //MyUserInfo myUserInfo = (MyUserInfo)request.getAttribute(MyCommon.MY_SESSION_KEY);

        //拦截的类名
        Class clazz = point.getTarget().getClass();
        //拦截的方法

        //System.out.println("执行了 类:" + clazz + " 方法:" + method + " 自定义请求地址:" + requestUrl);

        try {
            return point.proceed(); //执行程序
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return throwable.getMessage();
        }
    }
}
